Page({
  data: {
    major: '',
    activeIndex: 0,
    found: false,
    activeNames: ['1'],
    major_name: [
      { 
        tname: "petroleum",
        data: [
          { text: "碳储科学与工程", class: "工学", code: "081508" },
          { text: "智能地球探测", class: "工学", code: "081406" },
          { text: "海洋油气工程", class: "矿业类", code: "081506" },
          { text: "新能源科学与工程", class: "能源动力类", code: "080503" },
          { text: "建筑环境与能源应用工程", class: "土木类", code: "081002" },
          { text: "油气储运工程", class: "矿业类", code: "081504" },
          { text: "石油工程", class: "矿业类", code: "081502" },
          { text: "资源勘查工程", class: "地质类", code: "081403" },
        ]
      },
      { 
        tname: "chemistry",
        data: [
          { text: "高分子材料与工程", class: "工学", code: "080407" },
          { text: "储能科学与工程", class: "储能科学与工程", code: "080504" },
          { text: "化工安全工程", class: "化工与制药类", code: "081301" },
          { text: "环境工程", class: "环境科学与工程类", code: "082502" },
          { text: "化学工程与工艺", class: "化工与制药类", code: "081301" },
          { text: "应用化学", class: "化学类", code: "070302" },
        ]
      },
      { 
        tname: "control",
        data: [
          { text: "智能装备与系统", class: "工学", code: "080806" },
          { text: "智能制造工程", class: "工学", code: "080213T" },
          { text: "自动化", class: "工学", code: "080801" },
          { text: "材料成型及控制工程", class: "工学", code: "080203" },
          { text: "电气工程及其自动化​", class: "工学", code: "080601" },
          { text: "机械设计制造及其自动化", class: "工学", code: "080202" },
        ]
      },
      { 
        tname: "economy",
        data: [
          { text: "数字经济", class: "经济学类", code: "020109T" },
          { text: "法学", class: "法学类", code: "030101" },
          { text: "汉语言文学", class: "中国语言文学类", code: "050101" },
          { text: "财务管理", class: "工商管理类", code: "120204" }
        ]
      },
      { 
        tname: "educate",
        data: [
          { text: "数字媒体艺术", class: "设计学类", code: "130508" },
          { text: "学前教育", class: "教育学类", code: "040106" },
          { text: "音乐学", class: "音乐与舞蹈学类", code: "130202" },
        ]
      },
      { 
        tname: "computer",
        data: [
          { text: "智能科学与技术", class: "工学", code: "080907" },
          { text: "英语", class: "外国语言文学类", code: "050201" },
          { text: "数据科学与大数据技术", class: "计算机类", code: "080910" },
          { text: "物联网工程", class: "计算机类", code: "080905" },
          { text: "智能科学与技术", class: "工学", code: "080907" },
          { text: "计算机科学与技术", class: "计算机类", code: "080901" },
          { text: "信息与计算科学", class: "数学类", code: "070102" },

        ]
      },
      { 
        tname: "medicine",
        data: [
          { text: "药学", class: "药学类", code: "100701" },
          { text: "护理学", class: "护理学类", code: "101101" },
        ]
      }
    ]

  },
  handleCollapseChange(event) {
    this.setData({
      activeIndex: event.detail
    });
  },
  onLoad(options) {
    this.setData({
      major: options.major
    });
    this.checkMajorExistence();
  },
  handleCollapseChange(event) {
    this.setData({
      activeIndex: event.detail
    });
  },

  checkMajorExistence() {
    const { major, major_name } = this.data;
    const found = major_name.some(item => item.tname === major);
    this.setData({ found });
  },
})